<template>
    <div style="padding: 30px;position: relative;height: 100%">
        <div class="content-author" v-show="showContent">
            <Card style="width:500px">
                <div>
                    <h2 style="margin-bottom: 15px">第三方授权码：</h2>
                    <input id='input_url2' v-model='authorCode' style='opacity: 0;position: absolute;' type="text">
                    <Input type="text" v-model="authorCode" disabled></Input>
                    <div style="display: flex;justify-content: flex-end;margin-top: 15px">
                        <Poptip
                                transfer
                                confirm
                                title="确定要清除授权码吗？"
                                @on-ok="clearCode">
                            <Button type="error">清除</Button>
                        </Poptip>
                        <Button  style="margin-left: 15px" type="primary" @click="copyTeamLink">复制</Button>
                    </div>
                </div>
            </Card>
        </div>
        <div v-show="showDefImg1" class="defGraphWrap">
            <div class="defGraph"></div>
            <div class="graphText">
                暂无授权，
                <Button type="primary" ghost style="margin-left: 5px;display: inline-block" @click="produceCode">生成授权码</Button>
            </div>
        </div>
    </div>
</template>
<script>
    import $ from 'jquery'
    export default {
        data () {
            return {
                showDefImg1:false,
                authorCode:'',
                showContent:false,
            }
        },
        mounted () {
            // 查看已有授权
            this.queryExait()
        },
        created(){

        },
        methods: {
            // 查看已有授权
            queryExait(){
                this.axios.get(`${this.baseURL}/identity/account/accessToken`)
                    .then(res=>{
                        if(res.data.code === 1){
                            this.showDefImg1 = false
                            this.showContent = true
                            this.authorCode = res.data.data.token
                        }else {
                            this.showDefImg1 = true
                            this.showContent = false
                        }
                    })
                    .catch(err=>{
                        console.log(err)
                    })
            },
            produceCode(){
                this.axios.post(`${this.baseURL}/identity/account/accessToken`)
                    .then(res=>{
                        if(res.data.code === 1){
                            this.showDefImg1 = false
                            this.showContent = true
                            this.authorCode = res.data.data.token
                        }else {
                            this.$Message.warning({
                                content:res.data.message,
                                duration:3,
                            })
                        }
                    })
                    .catch(err=>{
                        console.log(err)
                    })
            },
            clearCode(){
                this.axios.delete(`${this.baseURL}/identity/account/accessToken`)
                    .then(res=>{
                        if(res.data.code === 1){
                            this.showDefImg1 = true
                            this.showContent = false
                            this.authorCode = ''
                            this.$Message.success({
                                content:'授权已清除',
                                duration:3,
                            })
                        }else {
                            this.$Message.warning({
                                content:res.data.message,
                                duration:3,
                            })
                        }
                    })
                    .catch(err=>{
                        console.log(err)
                    })
            },
            copyTeamLink(){
                var input = $('#input_url2');
                input.select();
                document.execCommand("Copy");
                this.$Message.success("复制成功");
            },
        },
    }
</script>
<style scoped>
    /*缺省图*/
    .defGraphWrap{
        width: 200px;
        height: 126px;
        position: absolute;
        top: 33%;
        left: 50%;
        margin-left: -100px;
        margin-top: -63px;
    }
    .defGraph{
        height: 126px;
        width: 157px;
        background: url("../../assets/globalIcon/defGraph.png") no-repeat center center;
        background-size: 157px 126px;
        margin: 0 auto;
    }
    .graphText{
        color: #888;
        font-size: 14px;
        text-align: center;
        margin-top: 20px;
    }
    .content-author{
        position: absolute;
        top: 25%;
        left: 50%;
        margin-left: -250px;
    }
</style>

